﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.SiteAdmin;
using Jzy.Model.SiteAdmin;
using Jzy.Core.Common.Web;
using Jzy.Core.Attach;

using Jzy.Core.Utility;
using Jzy.Common;

namespace Jzy.Web.SiteAdmin.FreindLink
{
    public partial class Edit : PageEdit
    {
        private FreindLinkBO _freindLink;
        private FreindLinkBO FreindLink
        {
            get
            {
                if (_freindLink == null)
                {
                    _freindLink = new FreindLinkBO();
                }
                return _freindLink;
            }

        }

       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (this.PKID != null)                
                {
                    DispInfo();
                }
            }
            AddAttr();
        }

        private void AddAttr()
        {
            // btnSave.Attributes.Add("onclick", "pic_upload(this,'" + lblMessage.ClientID + "','" + pnlMain.ClientID + "');");
        }

        private void DispInfo()
        {
            FreindLinkInfo info = this.FreindLink.GetInfo(this.PKID);
            EntityUtil.SetControl(pnlMain, info);

            if (!string.IsNullOrEmpty(info.ImagePath))
            {
                img.Visible = true;
                img.ImageUrl = info.ImageAbsPath;
                lnkImage.HRef = info.ImageAbsPath;
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            
                UserImage userImage = new UserImage(TableName.CmsFreindLink);
                FreindLinkInfo info = this.FreindLink.GetInfo(PKID);
                EntityUtil.SetEntity(pnlMain, info);

                if (fileImage.FileName != "")
                {
                    if (!string.IsNullOrEmpty(info.ImagePath))
                    {
                        this.FreindLink.DeleteImage(info.ID);
                    }

                    info.ImagePath = userImage.Save(fileImage.PostedFile, AppConfig.FreindLinkImageSize);
                }

                this.FreindLink.Save(info);
                JSUtil.RefreshView();
           
        }
    }
}
